cmake_minimum_required(VERSION 3.23)
project(CTKTEST)
# debug需要覆盖对应的dll, 并且需要删除configuration文件夹，让它重新生成
#指定C++标准
set(CMAKE_CXX_STANDARD 17)
#指定输出目录
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/output)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/output)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/output)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/output)
#自动编译QT文件
#set(CMAKE_PREFIX_PATH "C:/Qt/6.5.1/msvc2019_64")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
#开启包含当前编译目录
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#指定QT版本和对应的库
set(QT_VERSION 5)
set(REQUIRED_LIBS Core Gui Widgets OpenGL Sql
        #        Core5Compat
        )
set(REQUIRED_LIBS_QUALIFIED Qt${QT_VERSION}::Core Qt${QT_VERSION}::Gui Qt${QT_VERSION}::Widgets Qt${QT_VERSION}::OpenGL Qt${QT_VERSION}::Sql
        #        Qt${QT_VERSION}::Core5Compat
        )
add_subdirectory(core)
add_subdirectory(about)
add_subdirectory(Hello)
#寻找QT库
find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src
        ${CMAKE_CURRENT_SOURCE_DIR}/third_party/CTK/include/ctk-0.1
        )
file(GLOB HEADERS
        ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h
        )
file(GLOB SOURCES
        ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
        )

file(GLOB UIS
        ${CMAKE_CURRENT_SOURCE_DIR}/src/*.ui
        )

if (CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "Debug"))
    file(GLOB LIB_CTK ${PROJECT_SOURCE_DIR}/third_party/CTK/libd/ctk-0.1/*.lib)
    link_directories(${PROJECT_SOURCE_DIR}/third_party/CTK/libd/ctk-0.1)
else ()
    file(GLOB LIB_CTK ${PROJECT_SOURCE_DIR}/third_party/CTK/lib/ctk-0.1/*.lib)
    link_directories(${PROJECT_SOURCE_DIR}/third_party/CTK/lib/ctk-0.1)
endif ()
# 指定格式为utf-8
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
# 拷贝对应的动态库到执行目录(不用手动拷贝)
#if (CMAKE_BUILD_TYPE STREQUAL "Debug")
#    file(COPY "${PROJECT_SOURCE_DIR}/third_party/CTK/libd/ctk-0.1/CTKCore.dll" DESTINATION ${PROJECT_SOURCE_DIR}/output)
#    file(COPY "${PROJECT_SOURCE_DIR}/third_party/CTK/libd/ctk-0.1/CTKPluginFramework.dll" DESTINATION ${PROJECT_SOURCE_DIR}/output)
#    file(COPY "${PROJECT_SOURCE_DIR}/third_party/CTK/libd/ctk-0.1/debug/liborg_commontk_eventadmin.dll" DESTINATION ${PROJECT_SOURCE_DIR}/output/libs/debug)
#    file(COPY "${PROJECT_SOURCE_DIR}/third_party/CTK/libd/ctk-0.1/debug/liborg_commontk_metatype.dll" DESTINATION ${PROJECT_SOURCE_DIR}/output/libs/debug)
#    file(COPY "${PROJECT_SOURCE_DIR}/third_party/CTK/libd/ctk-0.1/debug/liborg_commontk_configadmin.dll" DESTINATION ${PROJECT_SOURCE_DIR}/output/libs/debug)
#    file(COPY "${PROJECT_SOURCE_DIR}/third_party/CTK/libd/ctk-0.1/debug/liborg_commontk_log.dll" DESTINATION ${PROJECT_SOURCE_DIR}/output/libs/debug)
#else ()
#    file(COPY "${PROJECT_SOURCE_DIR}/third_party/CTK/lib/ctk-0.1/CTKCore.dll" DESTINATION ${PROJECT_SOURCE_DIR}/output)
#    file(COPY "${PROJECT_SOURCE_DIR}/third_party/CTK/lib/ctk-0.1/CTKPluginFramework.dll" DESTINATION ${PROJECT_SOURCE_DIR}/output)
#    file(COPY "${PROJECT_SOURCE_DIR}/third_party/CTK/lib/ctk-0.1/debug/liborg_commontk_eventadmin.dll" DESTINATION ${PROJECT_SOURCE_DIR}/output/libs/debug)
#    file(COPY "${PROJECT_SOURCE_DIR}/third_party/CTK/lib/ctk-0.1/debug/liborg_commontk_metatype.dll" DESTINATION ${PROJECT_SOURCE_DIR}/output/libs/debug)
#    file(COPY "${PROJECT_SOURCE_DIR}/third_party/CTK/lib/ctk-0.1/debug/liborg_commontk_configadmin.dll" DESTINATION ${PROJECT_SOURCE_DIR}/output/libs/debug)
#    file(COPY "${PROJECT_SOURCE_DIR}/third_party/CTK/lib/ctk-0.1/debug/liborg_commontk_log.dll" DESTINATION ${PROJECT_SOURCE_DIR}/output/libs/debug)
#endif ()
#使用指定的源文件来生成目标可执行文件
add_executable(${PROJECT_NAME} WIN32 main.cpp ${HEADERS} ${SOURCES} ${UIS})
target_link_libraries(${PROJECT_NAME} ${REQUIRED_LIBS_QUALIFIED} ${LIB_CTK})
